package com.htfyun.eink.pw.core.manager;

import android.content.Context;

/**
 * 需要调用 {@link EinkManagerInstance#initManager(Context)} 后才能使用.
 */
public class EinkManagerHelper {

    private static final int SFC_SCMD_DITHERTYPE = 1002;
    private static final int SFC_SCMD_SCREENSET = 1005;

    private static final int EINK_FRWKCMD_BASE = 2000;
    private static final int EINK_FRWKCMD_END = 3000;
    private static final int EINK_CMD_SET_GUESTURE = (EINK_FRWKCMD_BASE);
    private static final int EINK_CMD_SET_SCREENMODE = (EINK_FRWKCMD_BASE + 1);
    private static final int EINK_MANACMD_BASE = 4000;
    private static final int EINK_MANACMD_END = 5000;
    private static final int EINK_MCMD_PWSTATUS = (EINK_MANACMD_BASE);  // 4000
    private static final int EINK_MCMD_TOUCHSTATUS = (EINK_MANACMD_BASE + 1); // 4001
    private static final int EINK_MCMD_DEBUG_FBDUMP = (EINK_MANACMD_BASE + 2); // 4002
    private static final int EINK_MCMD_DEBUG_FRMDLY = (EINK_MANACMD_BASE + 3); // 4003
    private static final int EINK_MCMD_DEBUG_LOGGER = (EINK_MANACMD_BASE + 4); // 4004
    private static final int EINK_MCMD_SHUTDOWN_SCREEN = (EINK_MANACMD_BASE + 5);

    public static void sendHwcCmd(int cmd, int[] param) {
        EinkManagerInstance.getInstance().sendHwcCmd(cmd, param);
    }

    public static void setGlobalGuestureEnabled(boolean enable) {
        int[] param = new int[2];
        param[0] = 1;
        param[1] = enable ? 1 : 0;
        sendHwcCmd(EINK_CMD_SET_GUESTURE, param);
    }

    public static void setStylusGuestureEnabled(boolean enable) {
        int[] param = new int[2];
        param[0] = 2;
        param[1] = enable ? 1 : 0;

        sendHwcCmd(EINK_CMD_SET_GUESTURE, param);
    }

    // 20220830: 设置刷新模式.gc : true,切换模式的时候进行GC刷新， false: 不进行GC刷新。
    // screenMode 的定义： EINK_SCREEN_MODE_CLEAR/SMOOTH/SPEED。
    public static void setScreenMode(int screenMode, boolean gc) {
        int[] param = new int[2];
        param[0] = screenMode;
        param[1] = gc ? 1 : 0;
        sendHwcCmd(EINK_CMD_SET_SCREENMODE, param);
    }

    // 20220911,add for screen-rotation.
    public static void freezeScreen(boolean freeze, int reason) {
        int[] param = new int[4];
        param[0] = 1;
        param[1] = freeze ? 1 : 0;
        param[2] = reason;
        param[3] = 0;
        sendHwcCmd(SFC_SCMD_SCREENSET, param);
    }

    public static void shutDownScreen(int reason, int reserve) {
        int[] param = new int[4];
        param[0] = reason;
        param[1] = reserve;
        param[2] = 0;
        param[3] = 0;
        sendHwcCmd(EINK_MCMD_SHUTDOWN_SCREEN, param);
    }

    // 20230411,add for choice dither-algo for diff window.
    // ditherType: 0/-1: use default, valid value: 1--11.
    // 3: sierra-64c, 4: atksn 64simd; 10: sierra-256c, 11: atksn 256c.
    public static void setDitherType(int ditherType) {
        int[] param = new int[4];
        param[0] = 9;
        param[1] = ditherType;
        param[2] = 0;
        param[3] = 0;
        sendHwcCmd(SFC_SCMD_DITHERTYPE, param);
    }

    /**
     * AUTO 刷新模式, 残影会比较重
     * @param enable
     */
    public static void enableFullUiAuto(boolean enable) {
        int[] param = new int[4];
        param[0] = 2;
        param[1] = enable ? 1 : 0;
        param[2] = 0;
        param[3] = 0;
        sendHwcCmd(1002, param);
    }


    /**
     * DU 数据模式, 残影比较轻
     * @param enable
     */
    public static void enableFullUiDU(boolean enable) {
        int[] param = new int[4];
        param[0] = 7;
        param[1] = enable ? 1 : 0;
        param[2] = 0;
        param[3] = 0;
        sendHwcCmd(1002, param);
    }

}
